﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    Nutrient nutrient;
    nutrientDAO dao;
    DataSet dataUpdate;

    protected void Page_Load(object sender, EventArgs e)
    {
        nutrient = new Nutrient();
        dao = new nutrientDAO();
        dataUpdate = new DataSet();
        dataUpdate = (DataSet) Session["NUTRI"];

        if (IsPostBack == false)
        {
            labelID.Text = nutrient.Id;
            labelID.Text = dataUpdate.Tables[0].Rows[0][0].ToString().ToUpper();
            txtUnit.Text = dataUpdate.Tables[0].Rows[0][1].ToString();
            txtName.Text = dataUpdate.Tables[0].Rows[0][2].ToString();
            dropType.SelectedValue = dataUpdate.Tables[0].Rows[0][3].ToString();
            txtCode.Text = dataUpdate.Tables[0].Rows[0][4].ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        update();
    }

    private void update()
    {
        nutrient.Id = labelID.Text;
        nutrient.Unit = txtUnit.Text;
        nutrient.Name = txtName.Text;
        nutrient.Type = dropType.SelectedValue.ToString();
        nutrient.Code = int.Parse(txtCode.Text);
        dao.update(nutrient);
        Response.Redirect("nutrient.aspx");
    }
}